var util = require('../../utils/util.js');
var page = 1;
var uid = 0;
var noMore = false;
Page({
  data: {
      result:[]
  },
  goHash (e) {
    let hash = e.currentTarget.dataset.hash
    this.setData({
      toView: hash
    })
  },
  goDetail:function(e){
    var topicid = e.currentTarget.dataset.topicid;
    wx.navigateTo({
      url: '../detail/detail?topicid='+topicid
    })
  },
  delLike: function(){
      //这是取消点赞
      util.api({
          method:"POST",
          data:{},
          success:function(responseData){
              console.log(responseData);
          }
      });
  },
  like: function(){
      //这是点赞
      util.api({
          method:"POST",
          data:{},
          success:function(responseData){
              console.log(responseData);
          }
      });
  },
  loadMore:function(){
      if(!noMore){
        page ++;
        this.load();
      }
  },
  onLoad: function(data){
    uid = data.uid || "";
    this.load();
  },
  load:function(){
    var that = this;
    util.api({
        data:{
            publickey:util.publiccode,
            ac:"topiclist",
            postuid:uid,
            toporder:1,
            page:page,
            num:20
        },
        success:function(responseData){
            var result = responseData.data;
            if(result && result.length > 0){
                result.forEach(function(m,i){
                if(m.photos)
                    result[i].photosData = m.photos.split(",");
                });
                that.setData({
                    result:that.data.result.concat(result)
                });
            }else{
                noMore = true;
            }
        }
    });
  }
})